package com.jic.data.service.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import cn.hutool.core.date.DateUtil;
import com.jic.data.constant.consist.ResponseCode;
import com.jic.data.exception.AppRuntimeException;
import com.jic.data.model.vo.response.HistogramChartResponse;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import javax.annotation.Resource;
import java.math.BigDecimal;
import com.jic.data.model.vo.response.SalesPlatformAmountResponse;
import com.jic.data.model.entity.SalesPlatformAmount;
import com.jic.data.mapper.SalesPlatformAmountMapper;
import com.jic.data.service.SalesPlatformAmountService;

import lombok.extern.slf4j.Slf4j;
/**
 * 接口实现类
 *
 * @author : 建投数据科技(山东)有限公司
 * @version : v1.0.0
 * @email :
 * @since : 2020-03-09 10:12:20
 */
@Service
@Slf4j
public class SalesPlatformAmountServiceImpl implements SalesPlatformAmountService {

	@Resource
	private SalesPlatformAmountMapper mapper;


	/**
	 * [销售概览-平台销售分布]
	 *
	 * @param request 不分页查询入参实体类
	 * @return 数据库查到的实体类列表
	 */
	@Override
	public HistogramChartResponse listAllRecord(SalesPlatformAmount request) {
		List<SalesPlatformAmount> list = mapper.selectBySelective(request);

		HistogramChartResponse response = new HistogramChartResponse();
		List<String> xDate = new ArrayList<>();

		List<Double> ytmall = new ArrayList<>();
		List<Double> yjd = new ArrayList<>();
		List<Double> ywechat = new ArrayList<>();

		list.stream().forEach( category -> {
			xDate.add(DateUtil.format(category.getSaleDate(),"yyyy-MM-dd"));
			yjd.add(category.getJdAmount().doubleValue() / 1000);
			ytmall.add(category.getTmallAmount().doubleValue() / 1000);
			ywechat.add(category.getWechatAmount().doubleValue() / 1000);
		});
		response.setX(xDate);
		response.setY1(ytmall);
		response.setY2(yjd);
		response.setY2(ywechat);

		return response;
	}




}
